# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=libpst
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.6.76.r78.g0dfabdc
pkgrel=1
pkgdesc="Outlook .pst file converter (mingw-w64)"
url="https://github.com/pst-format/libpst"
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
arch=('any')
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
  "${MINGW_PACKAGE_PREFIX}-libgsf"
  "${MINGW_PACKAGE_PREFIX}-libiconv"
  "${MINGW_PACKAGE_PREFIX}-zlib"
  "${MINGW_PACKAGE_PREFIX}-libgd"
  "${MINGW_PACKAGE_PREFIX}-libsystre"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-docbook-xsl"
  "${MINGW_PACKAGE_PREFIX}-doxygen"
  "${MINGW_PACKAGE_PREFIX}-graphviz"
  "autoconf-archive"
  "xmlto"
  "docbook-xsl"
  "git"
)
_commit="0dfabdc07bf31da628aa3d67138ad44d98583d1f"
source=("git+https://github.com/pst-format/libpst#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${_realname}"

  git describe --tags "${_commit}" | sed 's/^libpst-//;s/\([^-]*-g\)/r\1/;s/-/./g;s/^v//g'
}

prepare() {
  cd "${_realname}"

  autoreconf -fvi
}

build() {
  cd "${_realname}"

  # Force older C++ standard to avoid conflicts with std::byte
  CXXFLAGS+=" -std=c++0x"

  # The code doesn't guard Unix only features properly, this disables them hackily
  export ac_cv_header_semaphore_h=no

  # out-of-tree builds fail
  ./configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}" \
    --enable-libpst-shared \
    --enable-python=no \
    --enable-shared

  make -C xml all
  make
}

package() {
  cd "${_realname}"

  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
